/* 
 * File:   main.cpp
 * Author: Tung Mai
 *
 * Created on June 18, 2010, 10:14 AM
 */

#include <stdlib.h>
#include <unistd.h>
#include <CoreAudio/CoreAudio.h>

#include "AudioRecorder.h"



int main(int argc, char** argv) {
    OSStatus err;
    AudioRecorder* pAudioRecorder = NULL;
    AudioStreamBasicDescription	AIFFFormat;

    AIFFFormat.mFormatID = kAudioFormatLinearPCM;
    AIFFFormat.mSampleRate = 22050.0;
    AIFFFormat.mChannelsPerFrame = 1;
    AIFFFormat.mBitsPerChannel = 16;
    AIFFFormat.mBytesPerPacket = AIFFFormat.mBytesPerFrame = AIFFFormat.mChannelsPerFrame * sizeof(SInt16);
    AIFFFormat.mFramesPerPacket = 1;
    AIFFFormat.mFormatFlags = kAudioFormatFlagIsBigEndian | kAudioFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
    
    pAudioRecorder = new AudioRecorder();

    err = pAudioRecorder->Configure("/Users/macos2/Desktop", "audio.aiff", &AIFFFormat);
	if(err != noErr)
	{
		delete pAudioRecorder; pAudioRecorder = NULL;
		return 1;
	}
    
    err = pAudioRecorder->Start();
    if (err)
    {
        printf("Start audio recorder failed with err: %d\n", err);
        return 1;
    }

    sleep(5);

    err = pAudioRecorder->Stop();
    if (err)
    {
        printf("Stop audio recorder failed with err: %d\n", err);
        return 1;
    }

    printf("Finished\n");
    
    delete pAudioRecorder;

    return (EXIT_SUCCESS);
}

